package src.com.doit.Demo08练习;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class GongSi {
    private double zongZiChan;
    private ArrayList<Employee> list;

    public double getZongZiChan() {
        return zongZiChan;
    }

    public void setZongZiChan(double zongZiChan) {
        this.zongZiChan = zongZiChan;
    }

    public ArrayList<Employee> getList() {
        return list;
    }

    public void setList(ArrayList<Employee> list) {
        this.list = list;
    }

    public GongSi() {
    }

    public GongSi(double zongZiChan, ArrayList<Employee> list) {
        this.zongZiChan = zongZiChan;
        this.list = list;
    }

    public void setGongZi(Employee e,double a) {
        e.setGongZi(a+e.getGongZi());
        show(e);
    }
    public void lucky() {
        Random r = new Random();
        Scanner sc = new Scanner(System.in);
        int i = r.nextInt(list.size());
        System.out.println("随机抽取到的幸运员工为:" + list.get(i).getName());
        System.out.print("请输入为其调薪的额度:");
        double e = sc.nextDouble();
        list.get(i).setGongZi(e + list.get(i).getGongZi());
        show(list.get(i));
    }

    private void show(Employee employee) {
        System.out.println("姓名:" + employee.getName());
        System.out.println("ID:" + employee.getId());
        System.out.println("存款:" + employee.getCunKuan() + "元");
        if (employee instanceof JingLi) {
            System.out.println("奖金:" + ((JingLi) employee).getJiangJin());
        }
        System.out.println("调薪后的工资为:" + employee.getGongZi() + "元");
    }

    public void show() {
        for (int i = 0; i < list.size(); i++) {
            System.out.println("姓名:" + list.get(i).getName());
            System.out.println("ID:" + list.get(i).getId());
            System.out.println("存款:" + list.get(i).getCunKuan() + "元");
            if (list.get(i) instanceof JingLi) {
                System.out.println("奖金:" + ((JingLi) list.get(i)).getJiangJin());
            }
            System.out.println("工资:" + list.get(i).getGongZi() + "元");
            System.out.println("-------------------------");
        }
    }

    public void pay() {
        for (int i = 0; i < list.size(); i++) {
            zongZiChan -= list.get(i).getGongZi();//总资产减去员工工资
            list.get(i).setCunKuan(list.get(i).getGongZi() + list.get(i).getCunKuan());//员工的存款计算
            if (list.get(i) instanceof JingLi) {
                zongZiChan -= ((JingLi) list.get(i)).getJiangJin();
                list.get(i).setCunKuan(((JingLi) list.get(i)).getJiangJin() + list.get(i).getGongZi() + list.get(i).getCunKuan());
            }
        }
    }
}
